package com.cwd.arm.inter.vo;

import com.cwd.arm.common.enums.ErrorEnum;
import com.cwd.arm.common.exception.ArmException;
import lombok.Data;

import java.io.Serializable;

/**
 * Created by yan on 21-11-9.
 */
@Data
public class ResponseVo<T> implements Serializable {

    private static final long serialVersionUID = -3819569459544701549L;

    private Integer code = 200;

    private String desc;

    private T data;

    private ResponseVo() {
    }

    public ResponseVo<T> success(T data) {
        this.data = data;
        this.code = ErrorEnum.SUCCESS.getCode();
        this.desc = ErrorEnum.SUCCESS.getName();
        return this;
    }

    public ResponseVo<T> success(T data,String desc) {
        this.code = ErrorEnum.SUCCESS.getCode();
        this.desc = desc;
        return this;
    }

    public ResponseVo<T> success() {
        this.code = ErrorEnum.SUCCESS.getCode();
        this.desc = ErrorEnum.SUCCESS.getName();
        return this;
    }

    public ResponseVo<T> ERROR() {
        this.code = ErrorEnum.ERROR.getCode();
        this.desc = ErrorEnum.ERROR.getName();
        return this;
    }

    public ResponseVo<T> ERROR(String errorMsg) {
        this.code = ErrorEnum.ERROR.getCode();
        this.desc = errorMsg;
        return this;
    }


    public ResponseVo<T> ERROR(ErrorEnum errorEnum) {
        this.code = errorEnum.getCode();
        this.desc = errorEnum.getName();
        return this;
    }


    public ResponseVo<T> ERROR(ErrorEnum errorEnum, String errorMsg) {
        this.code = errorEnum.getCode();
        this.desc = errorMsg;
        return this;
    }

    public ResponseVo<T> ERROR(ArmException armException) {
        this.code = armException.getCode();
        this.desc = armException.getMsg();
        return this;
    }

    public static <E> ResponseVo<E> BUILDER() {
        return new ResponseVo();
    }

}
